﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Edge.Common.ComponentModel.Parameters;
using Edge.Common.Services;
using Edge.WebCode;
using Shop.Business.Domain.Catalog;
using Shop.Business.Domain.Orders;
using Shop.Web.AppCode;

namespace Shop.Web.AjaxPages.Popup
{
    public partial class ChangeSize : ShopBasePage
    {
        [QueryParameter(IsRequired = false)]
        public string CallBackFunction;

        [QueryParameter(IsRequired = false)]
        public string CallBackIds;

        [QueryParameter(IsRequired = false)]
        public string CallBackNames;

        [QueryParameter("id",IsRequired = true)]
        public int OrderItemId;

        private Guid? guid;
        protected OrderItem _orderItem;

        public Guid GUID
        {
            get
            {
                if (guid == null)
                    guid = Guid.NewGuid();
                return (Guid)guid;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            WebParameterAttribute.SetValues(this, Request);
            _orderItem = Locator.GetService<IOrderItemManager>().Load(OrderItemId);
            lblDraft.Visible = _orderItem.Order.OrderStatus == OrderStatus.Draft;
            Dictionary<string,List<Product>> dictionary = new Dictionary<string,List<Product>>();
            ProductGroup productGroup = _orderItem.Product.Group;
            foreach (Product product in productGroup.Products)
            {
                if (!dictionary.Keys.Contains(product.BrandArt))
                    dictionary.Add(product.BrandArt, new List<Product>());
                dictionary[product.BrandArt].Add(product);
            }
            hdnProdId.Value = _orderItem.Product.Id.ToString();
            rprBrandArt.DataSource = dictionary;
            rprBrandArt.DataBind();
        }
    }
}
